home *** CD-ROM | disk | FTP | other *** search
- Path: news.informatik.uni-kiel.de!ma
- From: ma@informatik.uni-kiel.de (Martin Ameskamp)
- Newsgroups: comp.lang.c++
- Subject: Re: How to print a enum variable's names
- Date: 5 Jan 1996 18:44:55 GMT
- Organization: Dept. of Computer Science, University of Kiel, FRG
- Message-ID: <4cjrj7$gr8@gutemine.informatik.uni-kiel.de>
- References: <4cjohq$k5u@lsi.lsil.com>
- NNTP-Posting-Host: rigel.informatik.uni-kiel.de
-
- In <4cjohq$k5u@lsi.lsil.com> song@lsil.com (Song Liang) writes:
-
- > Suppose you have a variable foo of type "enum bar_type {CAR TRUCK VAN}", if
- >you do "cout << foo", it will print either 0, 1 or 2. Is there a simple trick
- >to print the names, i.e CAR, TRUCK or VAN?
-
- > Thanks in advance.
-
- Yes: :-)
-
- switch (foo){
- case CAR: cout << "CAR"; break;
- case TRUCK: cout << "TRUCK"; break;
- case VAN: cout << "VAN"; break;
- }
-
- Probably not what you wanted, but there's no 'automatic' way
- to do this.
-
- Martin
-